import { Component, OnInit } from '@angular/core';
import {HeroService} from "../hero.service";
import {Hero} from "../hero";
import {Router} from "@angular/router";

@Component({
  selector: 'app-heros',
  templateUrl: './heros.component.html',
  styleUrls: ['./heros.component.css'],
  providers:[HeroService]
})
export class HerosComponent implements OnInit {
  ngOnInit(): void {
    this.heroService.getHeros().then(heros => this.heros = heros);
  }
  constructor(private heroService:HeroService,private router:Router){ }
  title:'标题';
  hero:Hero = {
    id:1,
    name:'ssss',
    age:0
  };
  heros: Hero[];
  selectedHero: Hero;
  goDetail(hero:Hero):void {
    console.log(hero);
    this.router.navigate(['/detail',hero.id]);
  }

}
